<?php
/**
 * FS 文件操作类测试
 */
class Test_FS {
    
    private $_tmpDir = '';

    public function  __construct() {

        $this->_tmpDir = FS::tmpDir('test');
    }

    public function testMkdir() {

        FS::mkdir($this->_tmpDir, 0666);
        return is_dir($this->_tmpDir);
    }

    public function testWrite() {
        
        $file = $this->_tmpDir . '/test/test.log';
        FS::write($file, 'test');
        return is_file($file);
    }

    public function testRead() {

        return FS::read($this->_tmpDir . '/test/test.log') == 'test';
    }

    public function testGetExt() {

        return FS::getExt($this->_tmpDir . '/test/test.log') == 'log';
    }

    public function testCopy() {

        FS::copy($this->_tmpDir . '/test/test.log', $this->_tmpDir . '/test/test2.log');
        return is_file($this->_tmpDir . '/test/test2.log');
    }

    public function testLsdir() {

        echo PHP_EOL, $this->_tmpDir, ':', PHP_EOL;
        $func = array($this, 'lsFilter');
        $files = FS::lsdir($this->_tmpDir, FS::LIST_ALL, true, $func);
        echo implode(PHP_EOL, $files);
        echo PHP_EOL;
        return $files && basename($files[0]) == 'test.log';
    }
    
    public function lsFilter($path, $relativePath, $filename) {

        return $filename == 'test.log';
    }

    public function testRemove() {

        FS::remove($this->_tmpDir . '/test/test.log');
        clearstatcache();
        return !is_file($this->_tmpDir . '/test/test.log');
    }

    public function testRmdir() {

        FS::rmdir($this->_tmpDir);
        clearstatcache();
        return !is_dir($this->_tmpDir);
    }
}